from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from pydantic_validation_decorator import NotBlank
from typing import Optional
from module_admin.annotation.pydantic_annotation import as_query




class Kq_log_dataModel(BaseModel):
    """
    考勤原始数据表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='序号')
    user_id: Optional[str] = Field(default=None, description='用户编号')
    user_name: Optional[str] = Field(default=None, description='用户姓名')
    am_pm: Optional[str] = Field(default=None, description='考勤时段')
    kh_work: Optional[str] = Field(default=None, description='考勤类型')
    punch_date: Optional[str] = Field(default=None, description='打卡日期')
    punch_time: Optional[str] = Field(default=None, description='打卡时间')
    punch_result: Optional[str] = Field(default=None, description='考勤结果')
    del_flag: Optional[str] = Field(default=None, description='删除标志')
    create_by: Optional[str] = Field(default=None, description='创建者')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')
    update_by: Optional[str] = Field(default=None, description='更新者')
    update_time: Optional[datetime] = Field(default=None, description='更新时间')
    remark: Optional[str] = Field(default=None, description='备注')

    @NotBlank(field_name='user_id', message='用户编号不能为空')
    def get_user_id(self):
        return self.user_id

    @NotBlank(field_name='user_name', message='用户姓名不能为空')
    def get_user_name(self):
        return self.user_name

    @NotBlank(field_name='am_pm', message='考勤时段不能为空')
    def get_am_pm(self):
        return self.am_pm

    @NotBlank(field_name='kh_work', message='考勤类型不能为空')
    def get_kh_work(self):
        return self.kh_work

    @NotBlank(field_name='punch_date', message='打卡日期不能为空')
    def get_punch_date(self):
        return self.punch_date

    @NotBlank(field_name='punch_time', message='打卡时间不能为空')
    def get_punch_time(self):
        return self.punch_time

    @NotBlank(field_name='punch_result', message='考勤结果不能为空')
    def get_punch_result(self):
        return self.punch_result


    def validate_fields(self):
        self.get_user_id()
        self.get_user_name()
        self.get_am_pm()
        self.get_kh_work()
        self.get_punch_date()
        self.get_punch_time()
        self.get_punch_result()




class Kq_log_dataQueryModel(Kq_log_dataModel):
    """
    考勤原始数据不分页查询模型
    """

    begin_time: Optional[str] = Field(default=None, description='开始时间')
    end_time: Optional[str] = Field(default=None, description='结束时间')


@as_query
class Kq_log_dataPageQueryModel(Kq_log_dataQueryModel):
    """
    考勤原始数据分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeleteKq_log_dataModel(BaseModel):
    """
    删除考勤原始数据模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    ids: str = Field(description='需要删除的序号')
